'''
Description: 
Author: Zilu
Date: 2021-11-07 20:30:51
Version: 
LastEditTime: 2021-12-02 16:28:39
LastEditors: Zilu
'''

# 可以使用Enum获得枚举类型的对象
from enum import Enum

Month = Enum('month', ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'))

for name, member in Month.__members__.items():
    print(name,'=>',member,',',member.value)

# value是默认赋值给成员的int常量，默认从1开始

# 也可以使用Enum的派生类，使用unique装饰器可以保证没有重复值
from enum import unique

@unique
class Weekday(Enum):
    Sun = '周日'
    Mon = '周一'
    Tue = '周二'
    Wed = '周三'
    Thur = '周四'
    Fri = '周五'
    Sat = '周六'

type(Weekday.Sun)
Weekday.__members__
Weekday.__members__.items()

# 可以使用成员名称引用，也可以使用value的值获取常量
print(Weekday.Sun)
print(Weekday(5))

# 练习：把Student的gender属性改造为枚举类型，可以避免使用字符串
class Gender(Enum):
    Male = 0
    Female = 1

class Student(object):
    def __init__(self, name, gender):
        self.name = name
        self.gender = gender



